package com.rrd.dw.mr.gzip.kafka;

import com.alibaba.fastjson.JSONObject;
import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.ylbusiness.YunXingScoreRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 银联-云杏分
 *
 * @author guoqiang
 */

public class YunXingScoreRecordParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 银联-云杏分
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        YunXingScoreRecord obj = (YunXingScoreRecord) model;
        JSONObject jsonDetail = obj.getDetail();
        StringBuilder sb = getBaseInfo(obj, successful);
        //信用评分
        sb.append(jsonDetail.getString("Score")).append(CRT001);
        //社交健康度
        sb.append(jsonDetail.getString("Health")).append(CRT001);
        //消费稳定度
        sb.append(jsonDetail.getString("Stability")).append(CRT001);
        //兴趣广泛度
        sb.append(jsonDetail.getString("Variety")).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_yinlian_yunxing_score_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.YUNXING_SCORE.toString();
    }

    @Override
    public String getComment() {
        return "银联-云杏分";
    }
}
